<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // const arr=new Array() == const arr=[1,2,3,4,5,6,7,8,9]  相当于一个构造方法用prototype共享方法

        // 最大值
        const arr=[1,2,3,4,5,6,7,8,9]
        Array.prototype.max=function(...arr){
            return Math.max(...arr)
        }
        console.log(arr.max(...arr));

        //使用this是指当前构造对象调用的就指向谁
        const arr1=[1,2,3,4,5,6,7,8,9]
        Array.prototype.max=function(){
            return Math.max(...this)
        }
        console.log(arr1.max());


    //    最小值
    const arrs=[1,2,3,4,5,6,7,8,9]
        Array.prototype.min=function(...arr){
            return Math.min(...arr)
        }
        console.log(arr.min(...arrs));
        
        //使用this是指当前构造对象调用的就指向谁
        const arr2=[1,2,3,4,5,6,7,8,9]
        Array.prototype.min=function(){
            return Math.min(...this)
        }
        console.log(arr2.min());



        // 求和  用this就可以简便点
        const arr3=[1,2,3,4,5,6,7,8,9]
        Array.prototype.sum=function(...array){
            let sun=0
            array.forEach(element => {
    
                sun+=element
            });
            return sun
        }
        console.log(arr3.sum(...arr3));
        // console.log(Array.prototype);
    </script>
</body>
</html>